package tq.com.upload;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import tq.com.tqim.R;

import static android.app.PendingIntent.getActivity;

public class TQUploadService extends Service {
    static private String TAG = "TQUploadService";
    @Override
    public void onCreate() {
        super.onCreate();
        android.os.Debug.waitForDebugger();
        Log.d(TAG, "onCreate: ");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "onStartCommand: ");

//        // 在API11之后构建Notification的方式
//    Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); //获取一个Notification构造器
//    Intent nfIntent = new Intent(this, TestActivity.class);
//
//    builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0))
//                .setContentTitle("下拉列表中的Title")
//                .setContentText("要显示的内容")
//                .setWhen(System.currentTimeMillis()); // 设置该通知发生的时间
//
//        Notification notification = builder.build(); // 获取构建好的Notification
//        notification.defaults = Notification.DEFAULT_SOUND; //设置为默认的声音
//
//        startForeground(1, notification);

        Notification.Builder builder = new Notification.Builder(this);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, TestActivity.class), 0);
        builder.setContentIntent(contentIntent);

        builder.setTicker("Foreground Service Start");
        builder.setContentTitle("Foreground Service");
        builder.setContentText("Make this service run in the foreground.");
        Notification notification = builder.build();
        startForeground(11, notification);

        return START_STICKY;//super.onStartCommand(intent, flags, startId);
    }



    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        Log.d(TAG, "onDestroy: ");
    }
}
